package com.itheima.book.manager.service;

import com.itheima.book.manager.dao.BookDao;
import com.itheima.book.manager.domain.Book;

public class BookService {
//    BookDao bookDao = new BookDao();
    private BookDao bookDao = new BookDao();
    public boolean addBook(Book book){
//        BookDao bookDao = new BookDao();
        boolean flag = bookDao.addBook(book);
//        if (flag){
//            return true;
//        }
        return flag;
    }

    public boolean isExistsBookId(String bookId){
        Book[] allBooks = bookDao.getAllBooks();
        for (int i = 0; i < allBooks.length; i++) {
            if (allBooks[i] != null) {
                if (allBooks[i].getBookId().equals(bookId)) {
                    return true;
                }
            }
        }
        return false;
    }

    public Book[] findAll(){
        Book[] allBooks = bookDao.getAllBooks();
        return allBooks;
    }

    public boolean deleteBookByBookId(String bookId){
        boolean flag = bookDao.deleteBookByBookId(bookId);
        return flag;
    }

    public void updateBookByBookId(Book book){
        bookDao.updateBookByBookId(book);
    }
}
